package ar.edu.sovietrussia.customcomponents.maincomponentviews;

import java.util.Map;

import org.apache.wicket.authroles.authorization.strategies.role.annotations.AuthorizeInstantiation;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Button;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.markup.html.panel.Panel;

import users.Person;
import ar.edu.sovietrussia.customcomponents.librarianstuff.LibrarianActionsComponent;
import ar.edu.sovietrussia.customcomponents.util.IDoReplaces;
import ar.edu.sovietrussia.customcomponents.util.IFeedbacker;
import ar.edu.sovietrussia.customcomponents.util.WrapperPanel;

@AuthorizeInstantiation("ADMIN")
public abstract class MainLibrarianComponent extends Panel implements IFeedbacker, IDoReplaces {

    private static final long serialVersionUID = 5782642735520738464L;

    public MainLibrarianComponent(final String id) {
        super(id);

        Person aModel = (Person) this.getSession().getAttribute("model");

        Form<String> form = new Form<String>("mainLibrarianForm");

        form.add(new Label("librarianNameLabel", aModel.getUserAccount().getRole().toString() + ": "
                + aModel.getSurname() + "," + aModel.getName()));

        // Button to Library Window
        form.add(new Button("library_button") {
            private static final long serialVersionUID = 3610707962001534656L;

            @Override
            public void onSubmit() {
                MainLibrarianComponent.this.replaceWith(new LibrarianActionsComponent(MainLibrarianComponent.this
                        .getId()) {

                    private static final long serialVersionUID = 1L;

                    @Override
                    public FeedbackPanel getFeedbackTarget() {
                        return MainLibrarianComponent.this.getFeedbackTarget();
                    }

                    @Override
                    public Map<String, WrapperPanel> getReplaceableComponents() {
                        return MainLibrarianComponent.this.getReplaceableComponents();
                    }

                });
            }
        });
        // Button to Personal Configuration Window
        form.add(new Button("personal_button") {
            private static final long serialVersionUID = 5119888790644143879L;

            @Override
            public void onSubmit() {
                MainLibrarianComponent.this.replaceWith(new MainUserComponentForLibrarians(MainLibrarianComponent.this
                        .getId()) {

                    private static final long serialVersionUID = 1L;

                    @Override
                    public FeedbackPanel getFeedbackTarget() {
                        return MainLibrarianComponent.this.getFeedbackTarget();
                    }

                    @Override
                    public Map<String, WrapperPanel> getReplaceableComponents() {
                        return MainLibrarianComponent.this.getReplaceableComponents();
                    }

                });
            }
        });
        this.add(form);
    }
}